package com.woniuxy.hibernate.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;





import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.woniuxy.hibernate.entity.User;
import com.woniuxy.hibernate.service.LoginService;


public class LoginAction extends ActionSupport{
	private User user;

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	
	HttpServletRequest request = ServletActionContext.getRequest();
	HttpSession session = request.getSession();
	LoginService loginService = new LoginService();
	
	public void validate(){
		boolean result = loginService.checkLogin(user.getUserName(), user.getPassWord());
		if (result == false)
		this.addFieldError("error", "用户或密码错误");
	}
	
	

	public String execute(){
			session.setAttribute("user", user);
			session.setAttribute("welcome", "欢迎进入系统，请选择");
			return "success";
	}
	
	
}
